const fs = require('fs');

let index = async (ctx, next) => {
    ctx.response.body = `<h1>index</h1><h1>首页</h1>`;
    await next();
};

let toIndex = async (ctx, next) => {
    let name = ctx.params.name;
    ctx.response.body = `<h1>你好${name}</h1>`;
    await next();
};

let a = async (ctx, next) => {
    // console.log('用户请求的url'+ctx.request.url);
    // fs.readFile("./a.html",(err,data)=>{
    //     if (err){
    //         console.log(err);
    //         return;
    //     }
    //     ctx.respond.body=data;
    // });

    let data = fs.readFileSync(path.join(path.resolve(__dirname,'..'),'../a.html'));
    ctx.response.body = data.toString();
    console.log('END=====>方法结束');
    console.log('收到请求');
    await next();
};

let image = async (ctx, next) => {
    let data = fs.readFileSync('../app.jpeg');
    ctx.response.type = 'image/jpeg';
    ctx.response.body = data;
};

module.exports = {
    'GET/index': index,
    'GET/toIndex/:name': toIndex,
    'GET/aa': a,
    'GET/image': image
};